Motivation

“The greatest value of a picture is when it forces us to notice what we never expected to see.” -John W. Tukey

Mistakes, biases, systematic errors and unexpected variability are commonly found in data regardless of applications. Failure to discover these problems often leads to flawed analyses and false discoveries. As an example, consider that measurement devices sometimes fail and not all summarization procedures, such as the mean() function in R, are designed to detect these. Yet, these functions will still give you an answer. Furthermore, it may be hard or impossible to notice an error was made just from the reported summaries.

Data visualization is a powerful approach to detecting these problems. We refer to this particular task as exploratory data analysis (EDA), coined by John Tukey. Many important methodological contributions to existing techniques in data analysis were initiated by discoveries made via EDA.

On a more positive note, data visualization can also lead to discoveries which would otherwise be missed if we simply subject the data to a battery of statistical summaries or procedures. Through this course, we make use of exploratory plots to motivate the analyses we choose.

Today, we are going to discuss some types of plots to avoid, better ways to visualize data, some principles to create good plots, and ways to use ggplot2 to create expository (intended to explain or describe something) graphs.

A lot of the material for this lecture was borrowed from

Example

The following figure is from Lippmann et al. 2006:

Nickel concentration and PM10 health effects.

Nickel concentration and PM10 health effects.

The following figure is from Dominici et al. 2007, in response to the work by Lippmann et al. above.

Nickel concentration and PM10 health effects.

Nickel concentration and PM10 health effects.

Generating Visualizations

In order to determine the effectiveness or quality of a visualization, we need to first understand two things:

  1. What is the question? Why are we building this visualization?

  2. Who is the audience?

No plot (or any statistical tool, really) can be judged without knowing the answers to those two questions. No plot or graphic exists in a vacuum. There is always context and other surrounding factors that play a role in determining a plot’s effectiveness.

Conversely, high-quality, well-made visualizations usually allow one to properly deduce what question is being asked and who the audience is meant to be. A good visualization tells a complete story in a single frame.

The act of visualizing data typically proceeds in two broad steps:

  1. Given the question and the audience, what type of plot should I make?

  2. Given the plot I intend to make, how can I optimize it for clarity and effectiveness?

Principles for Developing Analytic Graphics

Initially, one must decide what information should be presented. The following principles for developing analytic graphics come from Edward Tufte’s book Beautiful Evidence.

  1. Show comparisons

  2. Show causality, mechanism, explanation

  3. Show multivariate data

  4. Integrate multiple modes of evidence

  5. Describe and document the evidence

  6. Content is king - good plots start with good questions

Principles for Optimizing Graphics

  1. Maximize the data/ink ratio – if “ink” can be removed without reducing the information being communicated, then it should be removed.

  2. Maximize the range of perceptual conditions – your audience’s perceptual abilities may not be fully known, so it’s best to allow for a wide range, to the extent possible (or knowable).

  3. Show variation in the data, not variation in the design

What’s sub-optimal about this plot?

What’s sub-optimal about this plot?

Some of these principles are taken from Edward Tufte’s Visual Display of Quantitative Information:

Plots to Avoid

This section is based on a talk by Karl W. Broman titled “How to Display Data Badly,” in which he described how the default plots offered by Microsoft Excel “obscure your data and annoy your readers” (here is a link to a collection of Karl Broman’s talks).

His lecture was inspired by the 1984 paper by H. Wainer: How to display data badly. American Statistician 38(2): 137–147. Dr. Wainer was the first to elucidate the principles of the bad display of data. However, according to Karl Broman, “The now widespread use of Microsoft Excel has resulted in remarkable advances in the field.” Here we show examples of “bad plots” and how to improve them in R.

Some general principles of bad plots

  • Display as little information as possible.
  • Obscure what you do show (with chart junk).
  • Use pseudo-3D and color gratuitously.
  • Make a pie chart (preferably in color and 3D).
  • Use a poorly chosen scale.
  • Ignore significant figures.

Examples of bad plots and suggestions on how to improve

Pie charts

Let’s say we are interested in the most commonly used browsers. Wikipedia has a table with the “usage share of web browsers” or the proportion of visitors to a group of web sites that use a particular web browser from July 2017.

Let’s say we want to report the results of the usage. The standard way of displaying these is with a pie chart:

If we look at the help file for pie():

It states:

“Pie charts are a very bad way of displaying information. The eye is good at judging linear measures and bad at judging relative areas. A bar chart or dot chart is a preferable way of displaying this type of data.”

To see this, look at the figure above and try to determine the percentages just from looking at the plot. Unless the percentages are close to 25%, 50% or 75%, this is not so easy. Simply showing the numbers is not only clear, but also saves on printing costs.

Instead of pie charts, try bar plots

If you do want to plot them, then a barplot is appropriate. Here we use the geom_bar() function in ggplot2. Note, there are also horizontal lines at every multiple of 10, which helps the eye quickly make comparisons across:

Notice that we can now pretty easily determine the percentages by following a horizontal line to the x-axis.

Polish your plots

While this figure is already a big improvement over a pie chart, we can do even better. When you create figures, you want your figures to be self-sufficient, meaning someone looking at the plot can understand everything about it.

Some possible critiques are:

  1. make the axes bigger
  2. make the labels bigger
  3. make the labels be full names (e.g. “Browser” and “Proportion of users”, ideally with units when appropriate)
  4. add a title

Let’s explore how to do these things to make an even better figure.

To start, go to the help file for theme()

We see there are arguments with text that control all the text sizes in the plot. If you scroll down, you see the text argument in the theme command requires class element_text. Let’s try it out.

To change the x-axis and y-axis labels to be full names, use xlab() and ylab()

Maybe a title

Next, we can also use the theme() function in ggplot2 to control the justifications and sizes of the axes, labels and titles.

To center the title

To create bigger text/labels/titles:

3D barplots

Please, avoid a 3D version because it obfuscates the plot, making it more difficult to find the percentages by eye.

Donut plots

Even worse than pie charts are donut plots.

The reason is that by removing the center, we remove one of the visual cues for determining the different areas: the angles. There is no reason to ever use a donut plot to display data.

QUESTION: Why are pie/donut charts so common?

Barplots as data summaries

While barplots are useful for showing percentages, they are incorrectly used to display data from two groups being compared. Specifically, barplots are created with height equal to the group means; an antenna is added at the top to represent standard errors. This plot is simply showing two numbers per group and the plot adds nothing:

Instead of bar plots for summaries, try box plots

If the number of points is small enough, we might as well add them to the plot. When the number of points is too large for us to see them, just showing a boxplot is preferable.

Let’s recreate these barplots as boxplots and overlay the points. We will simulate similar data to demonstrate one way to improve the graphic above.

Notice how much more we see here: the center, spread, range, and the points themselves. In the barplot, we only see the mean and the standard error (SE), and the SE has more to do with sample size than with the spread of the data.

This problem is magnified when our data has outliers or very large tails. For example, in the plot below, there appears to be very large and consistent differences between the two groups:

However, a quick look at the data demonstrates that this difference is mostly driven by just two points.

Use log scale if data includes outliers

A version showing the data in the log-scale is much more informative.

Barplots for paired data

A common task in data analysis is the comparison of two groups. When the dataset is small and data are paired, such as the outcomes before and after a treatment, two-color barplots are unfortunately often used to display the results.

Instead of paired bar plots, try scatter plots

There are better ways of showing these data to illustrate that there is an increase after treatment. One is to simply make a scatter plot, which shows that most points are above the identity line. Another alternative is to plot the differences against the before values.

Too many significant digits

By default, statistical software like R returns many significant digits. This does not mean we should report them. Cutting and pasting directly from R is a bad idea since you might end up showing a table, such as the one below, comparing the heights of basketball players:

##              SG       PG        C       PF       SF
## team 1 68.88065 73.07480 81.80948 76.60455 82.23521
## team 2 70.05272 66.86024 74.64847 72.70140 78.55640
## team 3 71.33653 73.63946 81.00483 78.56787 77.86893
## team 4 73.36414 81.01021 81.68293 76.90146 77.35226
## team 5 72.63738 69.31895 83.66281 81.17280 82.39133
## team 6 68.99188 75.50274 79.36564 75.77514 78.68900
## team 7 73.51017 74.59772 82.09829 73.95492 78.32287
## team 8 73.46524 71.05953 77.88069 76.44808 73.86569

We are reporting precision up to 0.00001 inches. Do you know of a tape measure with that much precision? This can be easily remedied:

##          SG   PG    C   PF   SF
## team 1 68.9 73.1 81.8 76.6 82.2
## team 2 70.1 66.9 74.6 72.7 78.6
## team 3 71.3 73.6 81.0 78.6 77.9
## team 4 73.4 81.0 81.7 76.9 77.4
## team 5 72.6 69.3 83.7 81.2 82.4
## team 6 69.0 75.5 79.4 75.8 78.7
## team 7 73.5 74.6 82.1 74.0 78.3
## team 8 73.5 71.1 77.9 76.4 73.9

Minimal figure captions

Recall the plot we had before:

What type of caption would be good here?

When creating figure captions, think about the following:

  1. Be specific

A plot of the proportion of patients who survived after three drug treatments.

  1. Label the caption

Figure 1. A plot of the proportion of patients who survived after three drug treatments.

  1. Tell a story

Figure 1. Drug treatment survival. A plot of the proportion of patients who survived after three drug treatments.

  1. Include units

Figure 1. Drug treatment survival. A plot of the proportion of patients who survived after three drug treatments (milligram).

  1. Explain aesthetics

Figure 1. Drug treatment survival. A plot of the proportion of patients who survived after three drug treatments (milligram). Three colors represent three drug treatments. Drug A results in largest survival proportion for the larger drug doses.

Final thoughts

In general, you should follow these principles:

  • Create expository graphs to tell a story (figure and caption should be self-sufficient; it’s the first thing people look at)
    • Be accurate and clear
    • Let the data speak
    • Make axes, labels and titles big
    • Make labels full names (ideally with units when appropriate)
    • Add informative legends; use space effectively
  • Show as much information as possible, taking care not to obscure the message

  • Science not sales: avoid unnecessary frills (especially gratuitous 3D)

  • In tables, every digit should be meaningful

Some further reading

  • N Cross (2011). Design Thinking: Understanding How Designers Think and Work. Bloomsbury Publishing.
  • J Tukey (1977). Exploratory Data Analysis.
  • ER Tufte (1983) The visual display of quantitative information. Graphics Press.
  • ER Tufte (1990) Envisioning information. Graphics Press.
  • ER Tufte (1997) Visual explanations. Graphics Press.
  • ER Tufte (2006) Beautiful Evidence. Graphics Press.
  • WS Cleveland (1993) Visualizing data. Hobart Press.
  • WS Cleveland (1994) The elements of graphing data. CRC Press.
  • A Gelman, C Pasarica, R Dodhia (2002) Let’s practice what we preach: Turning tables into graphs. The American Statistician 56:121-130.
  • NB Robbins (2004) Creating more effective graphs. Wiley.
  • Nature Methods columns